{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import codecs\n",
    "import csv\n",
    "import time\n",
    "import os\n",
    "import re\n",
    "import gzip\n",
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "PATH_TO_DATA = 'Data/'\n",
    "PATH_TO_DATA_UK = PATH_TO_DATA+\"ukwiki/\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "UKWIKI_ART_FNMS = []\n",
    "for file in os.listdir(PATH_TO_DATA_UK):\n",
    "    if re.match(r\"ukwiki-20180620-pages-meta-current\\d{2}-p\\d+p\\d+.xml_art.csv.gz\", file):\n",
    "        UKWIKI_ART_FNMS.append(file)  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def unpack(file_name):\n",
    "    file_name_new = file_name.replace(\".gz\",\"\")\n",
    "    with gzip.open(file_name, 'rb') as f_in, open(file_name_new, 'wb') as f_out:\n",
    "        f_out.writelines(f_in)\n",
    "    return file_name_new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def pack_and_remove(file_name):\n",
    "    file_name_new = file_name+'.gz'\n",
    "    with open(file_name, 'rb') as f_in, gzip.open(file_name_new, 'wb') as f_out:\n",
    "        f_out.writelines(f_in)\n",
    "    os.remove(file_name)\n",
    "    return file_name_new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Data/ukwiki/ukwiki-20180620-pages-meta-current01-p1p5503930.xml_art.csv.gz\n",
      "total_links_count : 5520671\n",
      "total_red_links_count : 514801\n",
      "df_title_count size: (378611, 2)\n",
      "Data/ukwiki/ukwiki-20180620-pages-meta-current02-p5503931p11007860.xml_art.csv.gz\n",
      "total_links_count : 11031490\n",
      "total_red_links_count : 1205062\n",
      "df_title_count size: (777741, 2)\n",
      "Data/ukwiki/ukwiki-20180620-pages-meta-current03-p11007861p16511790.xml_art.csv.gz\n",
      "total_links_count : 16543016\n",
      "total_red_links_count : 2207420\n",
      "df_title_count size: (1316184, 2)\n",
      "Data/ukwiki/ukwiki-20180620-pages-meta-current04-p16511791p22015720.xml_art.csv.gz\n",
      "total_links_count : 22046931\n",
      "total_red_links_count : 2838280\n",
      "df_title_count size: (1553776, 2)\n"
     ]
    }
   ],
   "source": [
    "total_links_count = 0\n",
    "total_red_links_count = 0\n",
    "df_title_count = None\n",
    "for fn in UKWIKI_ART_FNMS:\n",
    "    fn = PATH_TO_DATA_UK+fn\n",
    "    print(fn)\n",
    "    fn_new = unpack(fn)\n",
    "    df_articles = pd.read_csv(fn_new, encoding='UTF-8', quotechar=\"\\\"\")\n",
    "    total_links_count += df_articles.shape[0]\n",
    "    df_red_links = df_articles[df_articles['is_red_link'] == True]\n",
    "    total_red_links_count += df_red_links.shape[0]\n",
    "    \n",
    "    df_title_count_tmp = pd.DataFrame(df_red_links.groupby('link_val').link_val.count())\n",
    "    df_title_count_tmp.columns = ['link']\n",
    "    df_title_count_tmp = df_title_count_tmp.reset_index(col_level=1)\n",
    "    df_title_count_tmp.columns = ['link_title', 'in_count']\n",
    "    \n",
    "    if df_title_count is not None:\n",
    "        df_title_count = df_title_count.append(df_title_count_tmp)        \n",
    "        #print(\"append\")\n",
    "    else:\n",
    "        df_title_count = df_title_count_tmp\n",
    "        #print(\"assign\")    \n",
    "    df_title_count = df_title_count.groupby('link_title').in_count.sum().copy()\n",
    "    df_title_count.columns = ['link']\n",
    "    df_title_count = df_title_count.reset_index()\n",
    "    df_title_count.columns = ['link_title', 'in_count']    \n",
    "    print(\"total_links_count : {}\".format(total_links_count))\n",
    "    print(\"total_red_links_count : {}\".format(total_red_links_count))\n",
    "    print(\"df_title_count size: {}\".format(df_title_count.shape))\n",
    "    os.remove(fn_new)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_title_count = df_title_count.sort_values(['in_count'], ascending=[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_title_count.to_csv(PATH_TO_DATA_UK+'ukwiki-20180620-red_name_count.csv', index = False, encoding='UTF-8', quotechar=\"\\\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>link_title</th>\n",
       "      <th>in_count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>(сузір'я)</td>\n",
       "      <td>15716</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1234002</th>\n",
       "      <td>Сеніор</td>\n",
       "      <td>1660</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1453806</th>\n",
       "      <td>ацетилювання</td>\n",
       "      <td>1619</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1134964</th>\n",
       "      <td>Подравський регіон‎</td>\n",
       "      <td>1298</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1458260</th>\n",
       "      <td>білок розвитку</td>\n",
       "      <td>942</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1163735</th>\n",
       "      <td>Південно-Східна Словенія‎</td>\n",
       "      <td>852</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1458258</th>\n",
       "      <td>білок внутрішньоклітинного сигналінгу</td>\n",
       "      <td>821</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1080011</th>\n",
       "      <td>Обсерваторія Галеакала</td>\n",
       "      <td>786</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>682869</th>\n",
       "      <td>Генрі Гольт</td>\n",
       "      <td>734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>612047</th>\n",
       "      <td>Велика_Британія</td>\n",
       "      <td>731</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>889629</th>\n",
       "      <td>Корадо Корлевіч</td>\n",
       "      <td>723</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1385885</th>\n",
       "      <td>Центр учбової літератури</td>\n",
       "      <td>721</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1263152</th>\n",
       "      <td>Станція Сінлун</td>\n",
       "      <td>719</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>913519</th>\n",
       "      <td>Кубок світу з боротьби</td>\n",
       "      <td>718</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1200579</th>\n",
       "      <td>Руденко Ірина Станіславівна</td>\n",
       "      <td>543</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1172908</th>\n",
       "      <td>Радченко Вероніка Вікторівна</td>\n",
       "      <td>542</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>602673</th>\n",
       "      <td>Вакуленко Олена Володимирівна</td>\n",
       "      <td>542</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1244921</th>\n",
       "      <td>Скуратович Олег Ярославович</td>\n",
       "      <td>537</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1226227</th>\n",
       "      <td>Світ (видавництво)</td>\n",
       "      <td>521</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1392905</th>\n",
       "      <td>Чанцева Ніна Іванівна</td>\n",
       "      <td>494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>772490</th>\n",
       "      <td>Дубович Іван Андрійович</td>\n",
       "      <td>487</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>309618</th>\n",
       "      <td>ODAS</td>\n",
       "      <td>462</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1080120</th>\n",
       "      <td>Обсерваторія Ондржейов</td>\n",
       "      <td>455</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>665161</th>\n",
       "      <td>Віржіні Раззано</td>\n",
       "      <td>450</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998527</th>\n",
       "      <td>Меган Шонессі</td>\n",
       "      <td>431</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>669115</th>\n",
       "      <td>Габрово (община)</td>\n",
       "      <td>415</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>390131</th>\n",
       "      <td>Soest</td>\n",
       "      <td>415</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>942661</th>\n",
       "      <td>Лиховцева Олена Олександрівна</td>\n",
       "      <td>415</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1192485</th>\n",
       "      <td>Родіонова Анастасія Іванівна</td>\n",
       "      <td>414</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>474713</th>\n",
       "      <td>Івета Бенешова</td>\n",
       "      <td>402</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571744</th>\n",
       "      <td>Бланкільйо</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571743</th>\n",
       "      <td>Бланкі Жером</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571741</th>\n",
       "      <td>Бланкове тестування</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571740</th>\n",
       "      <td>Бланко, Грісельда</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571739</th>\n",
       "      <td>Бланко Нез</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571738</th>\n",
       "      <td>Бланко (фільм)</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571737</th>\n",
       "      <td>Бланко (телескоп)</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571736</th>\n",
       "      <td>Бланкенхайм (Зангерхаузен)</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571735</th>\n",
       "      <td>Бланкенроде</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571756</th>\n",
       "      <td>Бланх Гертруда</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571757</th>\n",
       "      <td>Бланчард Райан</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571758</th>\n",
       "      <td>Бланчард Ріан</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571771</th>\n",
       "      <td>Бланш Грей</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571780</th>\n",
       "      <td>Бланш Крейг</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571778</th>\n",
       "      <td>Бланш Жак-Еміль</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571777</th>\n",
       "      <td>Бланш Дюбуа</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571776</th>\n",
       "      <td>Бланш Дюбоїс</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571775</th>\n",
       "      <td>Бланш Думер</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571774</th>\n",
       "      <td>Бланш Дуглас</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571773</th>\n",
       "      <td>Бланш Делакруа</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571770</th>\n",
       "      <td>Бланш Гардін</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571759</th>\n",
       "      <td>Бланш (гора)</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571769</th>\n",
       "      <td>Бланш Вудсайд</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571767</th>\n",
       "      <td>Бланш Бінглі</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571766</th>\n",
       "      <td>Бланш Бретонська</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571764</th>\n",
       "      <td>Бланш Баймштейн</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571762</th>\n",
       "      <td>Бланш (хребет)</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571761</th>\n",
       "      <td>Бланш (фільм)</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>571760</th>\n",
       "      <td>Бланш (станція метро)</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1553775</th>\n",
       "      <td>ﾟ</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1553776 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    link_title  in_count\n",
       "45                                   (сузір'я)     15716\n",
       "1234002                                 Сеніор      1660\n",
       "1453806                           ацетилювання      1619\n",
       "1134964                    Подравський регіон‎      1298\n",
       "1458260                         білок розвитку       942\n",
       "1163735              Південно-Східна Словенія‎       852\n",
       "1458258  білок внутрішньоклітинного сигналінгу       821\n",
       "1080011                 Обсерваторія Галеакала       786\n",
       "682869                             Генрі Гольт       734\n",
       "612047                         Велика_Британія       731\n",
       "889629                         Корадо Корлевіч       723\n",
       "1385885               Центр учбової літератури       721\n",
       "1263152                         Станція Сінлун       719\n",
       "913519                  Кубок світу з боротьби       718\n",
       "1200579            Руденко Ірина Станіславівна       543\n",
       "1172908           Радченко Вероніка Вікторівна       542\n",
       "602673           Вакуленко Олена Володимирівна       542\n",
       "1244921            Скуратович Олег Ярославович       537\n",
       "1226227                     Світ (видавництво)       521\n",
       "1392905                  Чанцева Ніна Іванівна       494\n",
       "772490                 Дубович Іван Андрійович       487\n",
       "309618                                    ODAS       462\n",
       "1080120                 Обсерваторія Ондржейов       455\n",
       "665161                         Віржіні Раззано       450\n",
       "998527                           Меган Шонессі       431\n",
       "669115                        Габрово (община)       415\n",
       "390131                                   Soest       415\n",
       "942661           Лиховцева Олена Олександрівна       415\n",
       "1192485           Родіонова Анастасія Іванівна       414\n",
       "474713                          Івета Бенешова       402\n",
       "...                                        ...       ...\n",
       "571744                              Бланкільйо         1\n",
       "571743                            Бланкі Жером         1\n",
       "571741                     Бланкове тестування         1\n",
       "571740                      Бланко, Грісельда          1\n",
       "571739                              Бланко Нез         1\n",
       "571738                          Бланко (фільм)         1\n",
       "571737                       Бланко (телескоп)         1\n",
       "571736              Бланкенхайм (Зангерхаузен)         1\n",
       "571735                             Бланкенроде         1\n",
       "571756                          Бланх Гертруда         1\n",
       "571757                          Бланчард Райан         1\n",
       "571758                           Бланчард Ріан         1\n",
       "571771                              Бланш Грей         1\n",
       "571780                             Бланш Крейг         1\n",
       "571778                         Бланш Жак-Еміль         1\n",
       "571777                             Бланш Дюбуа         1\n",
       "571776                            Бланш Дюбоїс         1\n",
       "571775                             Бланш Думер         1\n",
       "571774                            Бланш Дуглас         1\n",
       "571773                          Бланш Делакруа         1\n",
       "571770                            Бланш Гардін         1\n",
       "571759                            Бланш (гора)         1\n",
       "571769                           Бланш Вудсайд         1\n",
       "571767                            Бланш Бінглі         1\n",
       "571766                        Бланш Бретонська         1\n",
       "571764                         Бланш Баймштейн         1\n",
       "571762                          Бланш (хребет)         1\n",
       "571761                           Бланш (фільм)         1\n",
       "571760                   Бланш (станція метро)         1\n",
       "1553775                                      ﾟ         1\n",
       "\n",
       "[1553776 rows x 2 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_title_count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>in_count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>1.553776e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>1.826698e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>1.388762e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1.571600e+04</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           in_count\n",
       "count  1.553776e+06\n",
       "mean   1.826698e+00\n",
       "std    1.388762e+01\n",
       "min    1.000000e+00\n",
       "25%    1.000000e+00\n",
       "50%    1.000000e+00\n",
       "75%    1.000000e+00\n",
       "max    1.571600e+04"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_title_count.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_count_by_count = pd.DataFrame(df_title_count.groupby('in_count').in_count.count())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_count_by_count.columns = ['link']\n",
    "df_count_by_count = df_count_by_count.reset_index()\n",
    "df_count_by_count.columns = ['count', 'in_count']  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_count_by_count = df_count_by_count.sort_values(['count'], ascending=[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>in_count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1177094</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>203920</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>68509</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>33237</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>18475</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   count  in_count\n",
       "0      1   1177094\n",
       "1      2    203920\n",
       "2      3     68509\n",
       "3      4     33237\n",
       "4      5     18475"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_count_by_count.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>in_count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>318.000000</td>\n",
       "      <td>3.180000e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>249.616352</td>\n",
       "      <td>4.886088e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>893.529776</td>\n",
       "      <td>6.706917e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>80.250000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>159.500000</td>\n",
       "      <td>4.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>248.750000</td>\n",
       "      <td>2.175000e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>15716.000000</td>\n",
       "      <td>1.177094e+06</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              count      in_count\n",
       "count    318.000000  3.180000e+02\n",
       "mean     249.616352  4.886088e+03\n",
       "std      893.529776  6.706917e+04\n",
       "min        1.000000  1.000000e+00\n",
       "25%       80.250000  1.000000e+00\n",
       "50%      159.500000  4.000000e+00\n",
       "75%      248.750000  2.175000e+01\n",
       "max    15716.000000  1.177094e+06"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_count_by_count.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_count_by_count.to_csv(PATH_TO_DATA_UK+'ukwiki-20180620-red_count_by_count.csv', index = False, encoding='UTF-8', quotechar=\"\\\"\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
